<template>
  <div class="app-container">
    <div class="body-div">
      <el-card>
        <template #header>
          <div class="card-header">
            <span>设计输入条件：</span>
            <RadioGroup
              v-model="groupModel"
              :options="radioSource"
              @change="handleRadioChange"
            />
            <el-button
              type="primary"
              style="margin-left: 15px"
              @click="addConditionType()"
              >添加工况</el-button
            >
            <el-button style="float: right" type="primary" @click="back()"
              >返回</el-button
            >
          </div>
        </template>
        <el-form
          :inline="true"
          :model="formData"
          :rules="rules"
          ref="formRef"
          label-width="100px"
        >
          <div class="form-row">
            <el-form-item label="温度：" prop="temperature">
              <el-input
                v-model="formData.temperature"
                style="width: 100px"
              ></el-input>
              ℃
            </el-form-item>
            <el-form-item label="烟气压力：" prop="pressure">
              <el-input
                v-model="formData.pressure"
                style="width: 140px"
              ></el-input>
              <el-select
                v-model="formData.pressureUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in pressureUnitSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-form-item>
            <el-form-item label="烟气流量：" prop="quantityFlow">
              <el-input
                v-model="formData.quantityFlow"
                style="width: 140px"
              ></el-input>
              <el-select
                v-model="formData.quantityFlowUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in quantityFlowUnitSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.quantityFlowType"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-form-item>
          </div>
        </el-form>
        <template #footer>
          <span style="font-size: 16px">组分</span>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">氮氧化物（入口烟气）：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.nox"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.noxUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in noxUnitSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.noxType"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.noxOUnit"
                @change="changeNox"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.noxO"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-model="formData.noxOUnit"
                @change="changeNox"
                style="width: 100px"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">二氧化硫：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.so2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.so2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in so2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.so2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.so2OUnit"
                style="width: 100px; margin-left: 10px"
                @change="changeSo2"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.so2O"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-model="formData.so2OUnit"
                style="width: 100px"
                @change="changeSo2"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">氧含量：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.o"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.ounit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.otype"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="10"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">水蒸气含量：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.h2o"></el-input
            ></el-col>
            <el-col :span="6">
              <el-select
                v-model="formData.h2oUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.h2oType"
                v-if="false"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="10"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">二氧化碳：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.co2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.co2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.co2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="4"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">一氧化碳：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.co"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.coUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.coType"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="4"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">氮气：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.n2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.n2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.n2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="4"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">氩气：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.ar2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.ar2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.ar2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="4"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">氢气：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.h2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.h2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in oSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.h2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="4"> </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">三氧化硫：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.so3"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.so3Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in quantityOtherSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.so3Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.so3OUnit"
                style="width: 100px; margin-left: 10px"
                @change="changeSo3()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.so3O"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-model="formData.so3OUnit"
                style="width: 100px"
                @change="changeSo3()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px" v-if="false">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">一氧化氮：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.no"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.noUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in quantityOtherSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.noType"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.noOUnit"
                style="width: 100px; margin-left: 10px"
                @change="changeNo()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.noO"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-model="formData.noOUnit"
                style="width: 100px"
                @change="changeNo()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px" v-if="false">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">二氧化氮：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.no2"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.no2Unit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in quantityOtherSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.no2Type"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.no2OUnit"
                style="width: 100px; margin-left: 10px"
                @change="changeNo2()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.no2O"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-model="formData.no2OUnit"
                style="width: 100px"
                @change="changeNo2()"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="3" style="text-align: right">
              <span class="col-title">颗粒物：</span></el-col
            >
            <el-col :span="4">
              <el-input v-model="formData.pm"></el-input
            ></el-col>
            <el-col :span="10">
              <el-select
                v-model="formData.pmUnit"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in parSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <el-select
                v-model="formData.pmType"
                style="width: 100px; margin-left: 10px"
                ><el-option
                  v-for="item in commonSource"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option></el-select
            ></el-col>
            <el-col :span="2" v-if="false">
              <span class="col-title">基准氧：</span></el-col
            >
            <el-col :span="4" v-if="false">
              <el-input v-model="formData.pmO"></el-input
            ></el-col>
            <el-col :span="4" v-if="false">
              <el-select
                v-show="formData.pmType != '2'"
                v-model="formData.pmOUnit"
                style="width: 100px"
                ><el-option
                  v-for="item in O2Source"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option
              ></el-select>
              <span v-show="formData.pmType === '2'" class="col-title">
                实际O²</span
              >
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-button style="margin: auto" type="primary" @click="save()"
              >保存</el-button
            >
            <el-button
              v-show="false"
              type="primary"
              style=""
              @click="addOhter()"
              >前置计算条件输入</el-button
            >
          </el-row></template
        >
      </el-card>
      <el-dialog
        v-model="addShowType"
        title="工况输入条件录入"
        width="40%"
        @close="handleDialogClose"
        :close-on-click-modal="false"
      >
        <!-- 表单内容 -->
        <el-form
          :model="formDialog"
          :rules="rulesDialog"
          ref="formRefDialog"
          label-width="120px"
        >
          <el-form-item label="其他工况类型：" prop="typeValue">
            <el-input
              v-model="formDialog.typeValue"
              placeholder="请输入工况名称"
            ></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" @click="handleSaveType">保存</el-button>
            <el-button @click="addShowType = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";
import { useRoute } from "vue-router";
import request from "@/utils/request";
import RadioGroup from "@/components/MSTN/radioGroup.vue";
import { ElMessage, ElPopover, ElButton, ElMessageBox } from "element-plus";
import { getDicts } from "@/api/system/dict/data";

const route = useRoute(); //接受传参用
const id = route.params.id;
const furnace = route.params.furnace; //炉号

const router = useRouter(); //页面跳转用

const formData = ref({});

const formRef = ref(null);
const rules = {
  temperature: [{ required: true, message: "请输入温度", trigger: "blur" }],
  pressure: [{ required: true, message: "请输入压力", trigger: "blur" }],
  quantityFlow: [{ required: true, message: "请输入流量", trigger: "blur" }],
};

const groupModel = ref("");

const pressureUnitSource = ref([]);

const quantityFlowUnitSource = ref([]);

const noxUnitSource = ref([]); //氮氧化物单位

const commonSource = ref([]);

const O2Source = ref([]); //氧气单位

const gasSource = ref([]); //气体单位

const so2Source = ref([]); //二氧化硫单位

const oSource = ref([]); //氧气单位

const quantityOtherSource = ref([]); //其他气体单位

const parSource = ref([]); //颗粒物单位

const conditionTypeSource = ref([]); //工况类型

const batchId = ref(""); //批次id

const url = ref("addProjectCondition");

const typeValue = ref("1");

const addShowType = ref(false);

const formDialog = ref({});
const formRefDialog = ref(null);
const rulesDialog = {
  typeValue: [{ required: true, message: "请输入工况名称！", trigger: "blur" }],
};

function back() {
  router.push(`/projects/projectData/detail/${id}`).then(() => {});
}

//获取基础数据
function getList() {
  request({
    url: "/system/project/" + id,
    method: "get",
    params: {},
  }).then((response) => {
    const responseData = response.data;
    url.value = "addProjectCondition";
    if (responseData.furnaceList.length > 0) {
      const conditionValue = responseData.furnaceList.filter(
        (item) => item.projectFurnaceId == furnace
      );
      if (conditionValue && conditionValue.length > 0) {
        //数据源赋值
        if (
          conditionValue[0].conditionList &&
          conditionValue[0].conditionList.length > 0
        ) {
          conditionTypeSource.value = conditionValue[0].conditionList;
          formData.value.conditionType =
            conditionValue[0].conditionList[0].conditionType;
          url.value = "updateProjectCondition";
          for (let i = 0; i < conditionValue[0].conditionList.length; i++) {
            radioSource.value.push({
              conditionType: conditionValue[0].conditionList[i].conditionType,
            });
          }
          formData.value = conditionValue[0].conditionList[0];
          groupModel.value = conditionValue[0].conditionList[0].conditionType;
        }
      }
    }

    //判断 如果刚开始进 则全都是湿基
    changeToWet();
  });
}

//吧数据转换为湿基
function changeToWet() {
  if (url.value == "addProjectCondition") {
    formData.value.quantityFlowType = "2";
    formData.value.noxType = "2";
    formData.value.so2Type = "2";
    formData.value.otype = "2";
    formData.value.h2oType = "2";
    formData.value.so3Type = "2";
    formData.value.co2Type = "2";
    formData.value.coType = "2";
    formData.value.n2Type = "2";
    formData.value.ar2Type = "2";
    formData.value.h2Type = "2";
    formData.value.noType = "2";
    formData.value.no2Type = "2";
    formData.value.pmType = "2";

    //渲染默认单位
    formData.value.pressureUnit = "2";
    formData.value.quantityFlowUnit = "1";
    formData.value.noxUnit = "3";
    formData.value.so2Unit = "4";
    formData.value.ounit = "1";
    formData.value.h2oUnit = "1";
    formData.value.co2Unit = "1";
    formData.value.coUnit = "1";
    formData.value.n2Unit = "1";
    formData.value.ar2Unit = "1";
    formData.value.h2Unit = "1";
    formData.value.so3Unit = "2";
    formData.value.noUnit = "2";
    formData.value.no2Unit = "2";
    formData.value.pmUnit = "1";
  }
}

//点击框选择
function handleRadioChange(value) {
  ElMessageBox.confirm(
    "确定不保存当前工况条件吗（如许保存请先前进行保存）？",
    "提示",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }
  )
    .then(() => {
      typeValue.value = value;
      const params = {
        projectId: id,
        conditionType: value,
      };
      request({
        url: "/system/condition/list",
        method: "get",
        params: params,
      }).then((response) => {
        if (response.rows.length > 0) {
          formData.value = response.rows[0];
          url.value = "updateProjectCondition";
        } else {
          formData.value = {};
          url.value = "addProjectCondition";
        }
        changeToWet();
      });
    })
    .catch(() => {
      typeValue.value = value;
      const params = {
        projectId: id,
        conditionType: value,
      };
      request({
        url: "/system/condition/list",
        method: "get",
        params: params,
      }).then((response) => {
        if (response.rows.length > 0) {
          formData.value = response.rows[0];
          url.value = "updateProjectCondition";
        } else {
          formData.value = {};
          url.value = "addProjectCondition";
        }
        changeToWet();
      });
    });
}

//保存按钮
function save() {
  if (groupModel.value == "" || radioSource.value.length == 0) {
    ElMessage.error("请先选择工况类型!");
    return;
  }
  //新增详情
  if (url.value == "addProjectCondition") {
    formData.value.projectId = id;
    formData.value.conditionType = groupModel.value;
    //如果是新的单子的话先更新状态
    const editStatus = ref({});
    editStatus.value.projectId = id;
    editStatus.value.projectStatus = "2";
    request({
      url: "/system/project/editProject",
      method: "post",
      data: editStatus.value,
    }).then((response) => {
      console.log(response);
    });
  }

  formData.value.temperatureLow = formData.value.temperature;
  formData.value.temperatureHigh = formData.value.temperature;

  formData.value.projectFurnaceId = furnace;
  request({
    url: "/system/condition/" + url.value,
    method: "post",
    data: formData.value,
    //params: formData.value,
  }).then((response) => {
    console.log(response);
    if (response.code == 200) {
      ElMessage.success("保存成功！");
    } else {
      ElMessage.error("保存失败");
    }
  });
}

//添加工况
function addConditionType() {
  addShowType.value = true;
}

const radioSource = ref([]);
function handleSaveType() {
  radioSource.value.push({
    conditionType: formDialog.value.typeValue,
  });
  groupModel.value = formDialog.value.typeValue;
  formData.value.conditionType = formDialog.value.typeValue;
  formData.value.projectConditionId = "";
  url.value = "addProjectCondition";
  addShowType.value = false;
}
function handleDialogClose() {}

function changeNoxUnit() {
  if (formData.value.noxUnit == "4") {
    formData.value.nox = ((formData.value.nox / 46) * 22.4).toFixed(2);
    formData.value.noxUnit = "1";
  } else if (formData.value.noxUnit == "119") {
    formData.value.nox = (
      ((formData.value.nox * formData.value.quantityFlow) / 1000000 / 46) *
      22.4
    ).toFixed(2);
    formData.value.noxUnit = "1";
  }
}

function changeNox() {
  return;
  const noxNum = ref(0);
  noxNum.value = formData.value.nox;
  if (formData.value.noxOUnit != "" && formData.value.o != "") {
    if (formData.value.noxType == "1" && formData.value.ounit == "1") {
      //干基转换单位
      if (formData.value.noxUnit == "4") {
        noxNum.value = ((formData.value.nox / 46) * 22.4).toFixed(2);
      }
      formData.value.noxO =
        (noxNum.value / (21 - formData.value.o)) *
        (21 - formData.value.noxOUnit);
      formData.value.noxO = formData.value.noxO.toFixed(2);
    } else {
      //湿基转换
      formData.value.noxO =
        (noxNum.value / 21) * (21 - formData.value.noxOUnit);
      formData.value.noxO = formData.value.noxO.toFixed(2);
    }
  } else {
    formData.value.noxO = "";
  }
}

function changeSo2() {
  return;
  if (formData.value.so2OUnit != "" && formData.value.o != "") {
    if (formData.value.so2Type == "1" && formData.value.ounit == "1") {
      formData.value.so2O =
        (formData.value.so2 / (21 - formData.value.o)) *
        (21 - formData.value.so2OUnit);
      formData.value.so2O = formData.value.so2O.toFixed(2);
    } else {
      //湿基转换
      formData.value.so2O =
        (formData.value.so2 / 21) * (21 - formData.value.so2OUnit);
      formData.value.so2O = formData.value.so2O.toFixed(2);
    }
  } else {
    formData.value.so2O = "";
  }
}

//二氧化硫单位改变
function changeSo2Unit() {
  if (formData.value.so2Unit != "" && formData.value.quantityFlow != "") {
    if (formData.value.so2Unit == "1") {
      formData.value.so2 = (
        (formData.value.so2 * formData.value.quantityFlow) /
        100
      ).toFixed(2);
      formData.value.so2Unit = "2";
    } else if (formData.value.so2Unit == "3") {
      formData.value.so2 = ((formData.value.so2 / 64) * 22.4).toFixed(2);
      formData.value.so2Unit = "2";
    } else if (formData.value.so2Unit == "4") {
      //mg/Nm3 变 Nm3/h
      formData.value.so2 = (
        ((formData.value.so2 * formData.value.quantityFlow) / 1000000 / 46) *
        22.4
      ).toFixed(2);
      formData.value.so2Unit = "2";
    }
  }
}

function changeSo3() {
  return;
  if (formData.value.so3OUnit != "" && formData.value.o != "") {
    if (formData.value.so3Type == "1" && formData.value.ounit == "1") {
      formData.value.so3O =
        (formData.value.so3 / (21 - formData.value.o)) *
        (21 - formData.value.so3OUnit);
      formData.value.so3O = formData.value.so3O.toFixed(2);
    } else {
      //湿基转换
      formData.value.so3O =
        (formData.value.so3 / 21) * (21 - formData.value.so3OUnit);
      formData.value.so3O = formData.value.so3O.toFixed(2);
    }
  } else {
    formData.value.so3O = "";
  }
}

function changeNo() {
  return;
  if (formData.value.noOUnit != "" && formData.value.o != "") {
    if (formData.value.noType == "1" && formData.value.ounit == "1") {
      formData.value.noO =
        (formData.value.no / (21 - formData.value.o)) *
        (21 - formData.value.noOUnit);
      formData.value.noO = formData.value.noO.toFixed(2);
    } else {
      //湿基转换
      formData.value.noO =
        (formData.value.no / 21) * (21 - formData.value.noOUnit);
      formData.value.noO = formData.value.noO.toFixed(2);
    }
  } else {
    formData.value.noO = "";
  }
}

function changeNo2() {
  return;
  if (formData.value.no2OUnit != "" && formData.value.o != "") {
    if (formData.value.no2Type == "1" && formData.value.ounit == "1") {
      formData.value.no2O =
        (formData.value.no2 / (21 - formData.value.o)) *
        (21 - formData.value.no2OUnit);
      formData.value.no2O = formData.value.no2O.toFixed(2);
    } else {
      //湿基转换
      formData.value.no2O =
        (formData.value.no2 / 21) * (21 - formData.value.no2OUnit);
      formData.value.no2O = formData.value.no2O.toFixed(2);
    }
  } else {
    formData.value.no2O = "";
  }
}

//获取单位等相关
function getUnit() {
  getDicts("mstn_pressure_unit").then((response) => {
    pressureUnitSource.value = response.data;
  });

  getDicts("mstn_ji").then((response) => {
    commonSource.value = response.data;
  });

  getDicts("mstn_quantity_flow_unit").then((response) => {
    quantityFlowUnitSource.value = response.data;
  });

 getDicts("mstn_nox_flow_unit").then((response) => {
    noxUnitSource.value = response.data;
  });
  

  getDicts("mstn_o2").then((response) => {
    O2Source.value = response.data;
  });

  getDicts("mstn_gas_unit").then((response) => {
    gasSource.value = response.data;
  });

  getDicts("mstn_par_unit").then((response) => {
    parSource.value = response.data;
  });

  getDicts("mstn_quantity_flow_unit_other").then((response) => {
    quantityOtherSource.value = response.data;
  });

  //二氧化硫单位
  getDicts("mstn_so2_unit").then((response) => {
    so2Source.value = response.data;
  });

  //氧含量单位
  getDicts("mstn_o_unit").then((response) => {
    oSource.value = response.data;
  });
}

onMounted(() => {
  getList();
  getUnit();
});
</script>

<style scoped>
.headtitle {
  margin-left: 10px;
  font-size: 18px;
}

.app-container {
  padding: 10px;
  height: 100%;
  width: 100%;
}

.body-div {
  width: 100%;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  overflow-y: auto;
}

:deep(.el-form .el-form-item__label) {
  font-weight: 300 !important;
  font-size: 13px !important;
}
.col-title {
  font-weight: 300;
  font-size: 13px;
  line-height: 35px;
}

:deep(.el-dialog__body) {
  height: 80px !important;
  padding: 10px;
}
</style>
